//
//  MainTabBarController.m
//  RZIM
//
//  Created by reyzhang on 2021/8/12.
//

#import "MainTabBarController.h"
#import "ChatConversationListViewController.h"
#import "ContactViewController.h"
#import "PersonalViewController.h"
#import "BaseNavigationController.h"
#import "ChatRoomViewController.h"
@interface MainTabBarController ()

@end

@implementation MainTabBarController

+ (void)initialize{
    
    // 设置tabbarItem统一样式
    NSMutableDictionary *attrs = [NSMutableDictionary dictionary];
    attrs[NSFontAttributeName] = [UIFont systemFontOfSize:10];
    attrs[NSForegroundColorAttributeName] = [UIColor colorWithRed:51/255.0 green:51/255.0 blue:51/255.0 alpha:1];
    
    NSMutableDictionary *selectedAttrs = [NSMutableDictionary dictionary];
    selectedAttrs[NSFontAttributeName] = attrs[NSFontAttributeName];
    selectedAttrs[NSForegroundColorAttributeName] = [UIColor colorWithRed:72/255.0 green:142/255.0 blue:255/255.0 alpha:1];
    
    UITabBarItem *item = [UITabBarItem appearance];
    [item setTitleTextAttributes:attrs forState:UIControlStateNormal];
    [item setTitleTextAttributes:selectedAttrs forState:UIControlStateSelected];
    
    
}

- (void)viewDidLoad {
    [super viewDidLoad];

    [self addChildVC];
}



- (void)addChildVC {
    
    //单聊，群聊会话
    [self setupChildVc:[ChatConversationListViewController new] title:@"会话" image:@"Tab_Message" selectedImage:@"Tab_Message_Sel"];
    
    //通讯录
    [self setupChildVc:[ContactViewController new] title:@"通讯录" image:@"Tab_Document" selectedImage:@"Tab_Document_Sel"];
    
    //聊天室
    [self setupChildVc:[ChatRoomViewController new] title:@"聊天室" image:@"Tab_Document" selectedImage:@"Tab_Document_Sel"];
    

    //我
    [self setupChildVc:[PersonalViewController new] title:@"我的" image:@"Tab_Contact" selectedImage:@"Tab_Contact_Sel"];

}



- (void)setupChildVc:(UIViewController *)vc title:(NSString *)title image:(NSString *)image selectedImage:(NSString *)selectedImage
{
    // 设置文字和图片
//    vc.navigationItem.title = title;
    vc.tabBarItem.title = title;
    vc.tabBarItem.image = [UIImage imageNamed:image];
    vc.tabBarItem.selectedImage = [UIImage imageNamed:selectedImage];
    vc.title = title;
    BaseNavigationController *nav = [[BaseNavigationController alloc] initWithRootViewController:vc];
    [self addChildViewController:nav];
}


@end
